package com.sali.design_pattern.d_strategy_pattern.lesson_02;

import com.sali.design_pattern.d_strategy_pattern.lesson_02.strategy.IPayService;
import com.sali.design_pattern.d_strategy_pattern.lesson_02.strategy.impl.AliPayService;
import com.sali.design_pattern.d_strategy_pattern.lesson_02.strategy.impl.BankPayService;
import com.sali.design_pattern.d_strategy_pattern.lesson_02.strategy.impl.WeixinPayService;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description:
 * @author: zhang hang
 * @date: 2023/3/26 13:27.
 * @version: 1.0
 */
public class PayStrategyFactory {

    public static final String ALI_PAY = "alipay";
    public static final String WEIXIN_PAY = "weixin";
    public static final String BANK_PAY = "bank";

    // 容器式对象管理
    private static Map<String, IPayService> payServiceMap = new ConcurrentHashMap<>();

    static {

        payServiceMap.put(ALI_PAY, new AliPayService());
        payServiceMap.put(WEIXIN_PAY, new WeixinPayService());
        payServiceMap.put(BANK_PAY, new BankPayService());
    }

    public static IPayService getPayInstance(String paykey) {
        if (!payServiceMap.containsKey(paykey)) {
            return payServiceMap.get(ALI_PAY);
        }
        return payServiceMap.get(paykey);
    }

}
